<?php
    // array for JSON response
    $response = array();
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
    // connecting to db
    $db = new DB_CONNECT();
    $stt = 1;
    // get newest comments with infomation user commented and detail comments from comment, user and place table
    $result = mysql_query('SELECT user.user_avatar_zing, place.place_name, place.place_id, user.user_name_zing, comment.detail_comment FROM comment, place, user WHERE comment.user_id = user.user_id '
            . 'and comment.place_id = place.place_id ORDER BY comment.time_comment DESC LIMIT 5') or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
            $response["comment"] = array();
            while ($row = mysql_fetch_array($result)) {
                    $comment = array(); 
                    $comment['user_avatar_zing'] = $row['user_avatar_zing'];
                    $comment['user_name'] = $row['user_name_zing'];
                    $comment['place_name'] = $row['place_name'];
                    $comment['place_id'] = $row['place_id'];
                    $comment['detail_comment'] = $row['detail_comment'];
                    $comment['stt'] = $stt;
                    $stt++;
                    // push single product into final response array
                    array_push($response['comment'],$comment);
            }
            // success
        $response["success"] = 1;
            echo json_encode($response);
    }
    else{
        $response["comment"] = "No comemnt";
        $response["success"] = 0;
            echo json_encode($response);
    }
?>